<?php

namespace App\Http\Controllers;
use DB;
use App\Http\Requests\WzconfigPostRequest;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class WebconfigController extends Controller 
{
    //查询网站配置表并显示
    public function getWebconfig(Request $request)
    {
    	$conf = DB::table('webcon')->where('id','=',1)->first();

    	// dd($conf);
    	return view('admin.webconfig.webconfig',['conf'=>$conf]);

    }
    //修改网站配置
    public function postUpdate(Request $request)
    {     
       // $a = '';
       $data = $request->only('wztit','wzkws','wzbq','wzdesc','wzsw');
       // dd($request->hasFile('wzlog'));
        if($request->hasFile('wzlog')){
                //随机文件名
                $name = md5(time()+rand(1,9999999));
                //获取后缀名
                $su = $request->file('wzlog')->getClientOriginalExtension();
                $arr = array('jpg','png','jpeg','tiff');
                //判断
                if(!in_array($su,$arr)){
                     echo '<script type="text/javascript">
                    alert("上传文件不合法");
                    location.href="http://mao.cn/test/add";
                    </script>';
                }
             // dd(14444);
            //将文件移动到指定目录下
            $request->file('wzlog')->move('./uploads/wzlog/',$name.'.'.$su);
            $a = '/uploads/wzlog/'.$name.'.'.$su;

        }
       
          

            $data['wzlog'] = $a;
            $result = DB::table('webcon')->update($data);
            return back();

          // if($a){
          //   $data['wzlog']=$a;
          // }

    	    
    }
           
  
}
